<template>
  <el-dialog
    title="进口商信息"
    :modal="false"
    :visible.sync="centerDialogVisible"
    width="50%"
    center
  >
    <el-card class="margin-top">
      <div slot="header" class="clearfix relative">
            <span
              class="title-icon"
              style="color:#0081ff;"
            >进口商信息</span
            >
      </div>
      <el-form size="mini" label-position="left" label-width="98px">
        <el-button
          type="success"
          size="mini"
          class="header-save-btn" style="margin-top: 72px;margin-right: 23px"
          @click="changeImportInfo"
        >
          保存
        </el-button>
        <el-row class="" :gutter="20">
          <el-col :span="12">
            <el-form-item prop="isVatAndEori">
              <div slot="label">自有VAT/EORI:</div>
              <el-select
                v-model="importInfo.isVatAndEori"
                placeholder="自有VAT/EORI"
                style="width:80px"
              >
                <el-option
                  v-for="(k, v) in yesNo"
                  :key="v"
                  :label="yesNo[v]"
                  :value="parseInt(v)"
                ></el-option>
              </el-select>
              <template v-if="importInfo.isVatAndEori == 1">
                <el-checkbox
                  style="color:#F59A23"
                  v-if="
                        forecastForm.isTaxFarming != 1 &&

                          ![330, 331, 334, 335, 336, 349, 371, 372].includes(
                            Number(forecastForm.countryId)
                          )
                      "
                  v-model="importInfo.isJiufangImporter"
                  @change="changeJiufangImporter"
                  :true-label="parseInt(1)"
                  :false-label="parseInt(0)"
                >{{
                  importInfo.isJiufangImporter
                  ? "已选择九方进口商"
                  : "选择九方进口商"
                  }}</el-checkbox
                >
                <span v-else style="margin-left:30%;color:green">{{
                      importInfo.isJiufangImporter ? "已选择九方进口商" : ""
                    }}</span>
                <el-button
                  v-if="
                        forecastForm.isTaxFarming != 1
                      "
                  class="margin-left-lg"
                  type="text"
                  @click="clickSelectBtn"
                >
                  选择客户进口商
                </el-button>
              </template>
            </el-form-item>
          </el-col>
          <div v-if="!importInfo.isJiufangImporter">
            <el-col :span="12">
              <el-form-item prop="importerLinkMan">
                <div slot="label">联系人:</div>

                <el-input
                  v-model="importInfo.importerLinkMan"
                  clearable
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item prop="importerCompanyName">
                <div slot="label">公司名:</div>
                <el-input
                  v-model="importInfo.importerCompanyName"
                  clearable
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item prop="importerPhone">
                <div slot="label">电话:</div>

                <el-input
                  v-model="importInfo.importerPhone"
                  clearable
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item prop="vat">
                <div slot="label">VAT:</div>

                <el-input
                  v-model="importInfo.vat"
                  clearable
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item prop="importerZipCode">
                <div slot="label">邮编:</div>

                <el-input
                  v-model="importInfo.importerZipCode"
                  clearable
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item prop="eori">
                <div slot="label">EORI:</div>

                <el-input
                  v-model="importInfo.eori"
                  clearable
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item prop="importerAddress">
                <div slot="label">详细地址:</div>

                <el-input
                  v-model="importInfo.importerAddress"
                  clearable
                />
              </el-form-item>
            </el-col>
          </div>
        </el-row>
      </el-form>
    </el-card>
  </el-dialog>
</template>

<script>
  import { ajax } from "@/store/yg/common/utils";
    export default {
      props: {
        data: {
          type: Object,
          default: function() {
            return {};
          }
        }
      },
      data() {
        return {
          yesNo: {
            1: "是",
            0: "否"
          },
          centerDialogVisible: false,
          importInfo: {
            id: 0,
            eoriIsCertified: 1, //认证
            isVatAndEori: 1, //自有VAT/EORI
            importerCompanyName: 1, //进口商公司名：
            importerAddress: 1, //进口商详细地址：
            importerZipCode: 1, //邮编
            importerLinkMan: 1, // 联系人
            importerPhone: 1, // 进口商联系人电话：
            vat: 1,
            eori: 1,
            isJiufangImporter: 1
          },
          forecastForm: {
            //运单ID
            id: "",
            countryId: "",
            mergerDeclarationNo: "", //合并报关单号
            isFba: "",
            customerActualWeight: "",
            customerVolume: "",
            provinceId: "",
            deliveryTerms: "",
            customerChargedWeight: "",
            loadingPort: "",
            isTaxFarming: "",
            customerTotalPackages: "",
            inStockChannel: "",
            isCustomerDeclaration: 0,
            dispatchAddressCode: "",
            dispatcher: "",
            dispatchLinkMan: "",
            dispatchPhone: "",
            dispatchProvince: "",
            dispatchCity: "",
            dispatchZipCode: "",
            dispatchAddress: "",
            dispatchAddress2: "",
            isBuyInsurance: 0,
            houseNumber: "",
            customerCalVolume: null,
            pickUpGoodsAddres: "",
            customerRemark: "123"
          },
        };
      },
      mounted() {
        this.initData();
      },
      methods: {
        //数据初始化
        initData(){
          this.importInfo = this.data;
          this.forecastForm = this.data;
        },
        changeJiufangImporter() {
          if (
            this.importInfo.isJiufangImporter &&
            this.importInfo.isJiufangImporter !== null &&
            this.importInfo.isJiufangImporter !== ""
          ) {
            this.importInfo.importerCompanyName = "";
            this.importInfo.importerLinkMan = "";
            this.importInfo.importerPhone = "";
            this.importInfo.vat = "";
            this.importInfo.eori = "";
            this.importInfo.importerAddress = "";
            this.importInfo.importerZipCode = "";
          }
        },
        clickSelectBtn() {
          this.selectImporterType = true;
          if (this.selectImporterType) {
            this.importInfo.isJiufangImporter = 0;
          }
        },
        changeImportInfo() {

            this.importInfo["id"] = this.data.id;
            this.importInfo["orderFlag"]=1;
            if (
              this.importInfo.isJiufangImporter &&
              this.importInfo.isJiufangImporter !== null &&
              this.importInfo.isJiufangImporter !== undefined
            ) {
              this.importInfo.importerCompanyName = "九方";
              this.importInfo.importerLinkMan = "九方";
              this.importInfo.importerPhone = "九方";
              this.importInfo.vat = "九方";
              this.importInfo.eori = "九方";
              this.importInfo.importerAddress = "九方";
              this.importInfo.importerZipCode = "九方";
            }
            var param = this.importInfo;

            ajax("changeImportInfo", param).then(
              res => {
                if (res.code != 200) {
                  if (null != res.message) {
                    this.$message.error(res.message);
                  } else {
                    this.$message.error("修改失败!");
                  }
                } else {
                  this.$message.success("已提交到待审批列表");
                  this.forecastForm = res.data;
                  this.stockInfo = res.data;
                }
              },
              error => {
                console.log(error);
              }
            );

        },
      },
    }
</script>

<style scoped>

</style>
